package com.example.tybei_lalojban_2;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.tools.LoadJSON;

import java.util.Map;

public class finish extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle s){
        super.onCreate(s);
        setContentView(R.layout.finish);
        Intent i=getIntent();
        Bundle b=i.getExtras();
        LoadJSON.gismu word=b.getParcelable("word");
        String lasts=b.getString("lasts");
        TextView word_name=findViewById(R.id.word),meaning=findViewById(R.id.meaning_finish),sentences=findViewById(R.id.sentences_finish),last=findViewById(R.id.last_finish);
        Button wrong=findViewById(R.id.unknown),right=findViewById(R.id.right);
        word_name.setText(word.name);
        String meanings="["+word.ciXing+ "] " +word.meaning;
        meaning.setText(meanings);
        last.setText(lasts);
        StringBuilder sb=new StringBuilder();
        for(Map.Entry<String,String> j:word.sentences.entrySet()){
            sb.append(j.getKey().replace("%",word.name).replace(new String(new char[word.name.length()]).replace("\0","_"),word.name));
            sb.append('\n');
            sb.append(j.getValue());
            sb.append('\n');
        }
        sentences.setText(sb.toString());
        wrong.setOnClickListener(v -> {
            Bundle bd=new Bundle();
            bd.putBoolean("known",false);
            i.putExtras(bd);
            setResult(0x011,i);
            finish();
        });
        right.setOnClickListener(v -> {
            Bundle bd=new Bundle();
            bd.putBoolean("known",true);
            i.putExtras(bd);
            setResult(0x011,i);
            finish();
        });
    }
}
